<!DOCTYPE html>
<html>
  <head>
    <meta charset='utf-8'>
    <meta content='width=device-width, initial-scale=1.0' name='viewport'>
    <meta content='' name='description'>
    <meta content='Nils Nordman' name='author'>
    <link href='/images/howl.png' rel='shortcut icon'>
    <title>Howl :: Spec - howl.Buffer</title>
    <link href="/stylesheets/bootstrap.min.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/syntax.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/howl.css" media="screen" rel="stylesheet" type="text/css" />
    <script src="https://code.jquery.com/jquery-1.12.3.min.js" type="text/javascript"></script>
    <script src="/javascripts/bootstrap.min.js" type="text/javascript"></script>
    
    <link href='//fonts.googleapis.com/css?family=Josefin+Slab' rel='stylesheet' type='text/css'>
    <link href='//fonts.googleapis.com/css?family=Open+Sans+Condensed:700' rel='stylesheet' type='text/css'>
  </head>
  <body class='doc doc_spec doc_spec_buffer_spec'>
    <div class='container'>
      <div class='masthead'>
        <ul class='nav nav-pills'>
          <li>
            <a href='/'>
              <span class='glyphicon glyphicon-home'></span>
              Home
            </a>
          </li>
          <li>
            <a href='/doc/'>
              <span class='glyphicon glyphicon-book'></span>
              Documentation
            </a>
          </li>
          <li>
            <a href='/blog/'>
              <span class='glyphicon glyphicon-bullhorn'></span>
              Blog
            </a>
          </li>
          <li>
            <a href='/contact.html'>
              <span class='glyphicon glyphicon-inbox'></span>
              Contact
            </a>
          </li>
        </ul>
      </div>
      <ol class="breadcrumb"><li><a href="/">Home</a></li><li><a href='../'>Howl 0.4 Documentation</a></li><li>Spec</li><li>Spec - howl.Buffer</li></ol>
      <div class="spec-group spec-group-1">&#x000A;&#x000A;<h1 id="howl.buffer">howl.Buffer</h1>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">text</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="k">with</span><span class="w"> </span><span class="nc">Buffer</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;    </span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">text</span></pre>&#x000A;&#x000A;<h4 id=".text-allows-setting-and-retrieving-the-buffer-text">.text allows setting and retrieving the buffer text</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Buffer</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">''</span><span class="w">&#x000A;</span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'Ipsum'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'Ipsum'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span></pre>&#x000A;&#x000A;<h4 id=".size-returns-the-size-of-the-buffer-text,-in-bytes">.size returns the size of the buffer text, in bytes</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">buffer</span><span class="p">(</span><span class="s1">'hello'</span><span class="p">).</span><span class="n">size</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">buffer</span><span class="p">(</span><span class="s1">'åäö'</span><span class="p">).</span><span class="n">size</span><span class="p">,</span><span class="w"> </span><span class="mi">6</span></pre>&#x000A;&#x000A;<h4 id=".length-returns-the-size-of-the-buffer-text,-in-characters">.length returns the size of the buffer text, in characters</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">(</span><span class="s1">'hello'</span><span class="p">).</span><span class="n">length</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">(</span><span class="s1">'åäö'</span><span class="p">).</span><span class="n">length</span></pre>&#x000A;&#x000A;<h4 id=".modified-indicates-and-allows-setting-the-modified-status">.modified indicates and allows setting the modified status</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Buffer</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">modified</span><span class="w">&#x000A;</span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hello'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">modified</span><span class="w">&#x000A;</span><span class="n">b</span><span class="p">.</span><span class="n">modified</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">false</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">modified</span><span class="w">&#x000A;</span><span class="n">b</span><span class="p">.</span><span class="n">modified</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">modified</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'hello'</span><span class="w"> </span><span class="c1">-- toggling should not have changed text</span></pre>&#x000A;&#x000A;<h4 id=".read_only-can-be-set-to-mark-the-buffer-as-read-only">.read_only can be set to mark the buffer as read-only</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'kept'</span><span class="w">&#x000A;</span><span class="n">b</span><span class="p">.</span><span class="n">read_only</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="kc">true</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">read_only</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'read%-only'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">append</span><span class="w"> </span><span class="s1">'illegal'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'read%-only'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">insert</span><span class="w"> </span><span class="s1">'illegal'</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'read%-only'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'illegal'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'kept'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="w">&#x000A;</span><span class="n">b</span><span class="p">.</span><span class="n">read_only</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">false</span><span class="w">&#x000A;</span><span class="n">b</span><span class="o">\</span><span class="n">append</span><span class="w"> </span><span class="s1">' yes'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'kept yes'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span></pre>&#x000A;&#x000A;<h4 id=".eol-is-&quot;\\n&quot;-by-default">.eol is &quot;\\n&quot; by default</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="s1">'\n'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">(</span><span class="s1">''</span><span class="p">).</span><span class="n">eol</span></pre>&#x000A;&#x000A;<h4 id=".properties-is-a-table">.properties is a table</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'table'</span><span class="p">,</span><span class="w"> </span><span class="nb">type</span><span class="w"> </span><span class="n">buffer</span><span class="p">(</span><span class="s1">''</span><span class="p">).</span><span class="n">properties</span></pre>&#x000A;&#x000A;<h4 id=".data-is-a-table">.data is a table</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'table'</span><span class="p">,</span><span class="w"> </span><span class="nb">type</span><span class="w"> </span><span class="n">buffer</span><span class="p">(</span><span class="s1">''</span><span class="p">).</span><span class="n">data</span></pre>&#x000A;&#x000A;<h4 id=".showing-is-true-if-the-buffer-is-currently-referenced-in-any-view">.showing is true if the buffer is currently referenced in any view</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">''</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">false</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">showing</span><span class="w">&#x000A;</span><span class="n">b</span><span class="o">\</span><span class="n">add_view_ref</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">true</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">showing</span></pre>&#x000A;&#x000A;<h4 id=".can_undo-returns-true-if-undo-is-possible,-and-false-otherwise">.can_undo returns true if undo is possible, and false otherwise</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Buffer</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">can_undo</span><span class="w">&#x000A;</span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'bar'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">can_undo</span><span class="w">&#x000A;</span><span class="n">b</span><span class="o">\</span><span class="n">undo</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">can_undo</span></pre>&#x000A;&#x000A;<h4 id="#buffer-returns-the-number-of-characters-in-the-buffer">#buffer returns the number of characters in the buffer</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="n">buffer</span><span class="p">(</span><span class="s1">'hello'</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="n">buffer</span><span class="p">(</span><span class="s1">'åäö'</span><span class="p">)</span></pre>&#x000A;&#x000A;<h4 id="tostring(buffer)-returns-the-buffer-title">tostring(buffer) returns the buffer title</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'hello'</span><span class="w">&#x000A;</span><span class="n">b</span><span class="p">.</span><span class="n">title</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'foo'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="nb">tostring</span><span class="p">(</span><span class="n">b</span><span class="p">),</span><span class="w"> </span><span class="s1">'foo'</span></pre>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id=".file-=-&lt;file&gt;">.file = &lt;file&gt;</h2>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">''</span></pre>&#x000A;&#x000A;<h4 id="sets-the-title-to-the-basename-of-the-file">sets the title to the basename of the file</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="p">.</span><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">file</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">title</span><span class="p">,</span><span class="w"> </span><span class="n">file</span><span class="p">.</span><span class="n">basename</span></pre>&#x000A;&#x000A;<h4 id="marks-the-buffer-as-not-modified">marks the buffer as not modified</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="p">.</span><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">file</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">modified</span></pre>&#x000A;&#x000A;<h4 id="clears-the-undo-history">clears the undo history</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="p">.</span><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">file</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">can_undo</span></pre>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id="when-&lt;file&gt;-exists">when &lt;file&gt; exists</h3>&#x000A;&#x000A;<h4 id="overwrites-any-existing-buffer-text-even-if-the-buffer-is-modified">overwrites any existing buffer text even if the buffer is modified</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'foo'</span><span class="w">&#x000A;</span><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">file</span><span class="p">.</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'yes sir'</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="p">.</span><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">file</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'yes sir'</span></pre>&#x000A;<div class="spec-group spec-group-4">&#x000A;&#x000A;<h4 id="and-the-buffer-is-not-modified">and the buffer is not modified</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'foo'</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="p">.</span><span class="n">modified</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">false</span></pre>&#x000A;&#x000A;<h4 id="sets-the-buffer-text-to-the-contents-of-the-file">sets the buffer text to the contents of the file</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">file</span><span class="p">.</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'yes sir'</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="p">.</span><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">file</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'yes sir'</span></pre>&#x000A;</div>&#x000A;</div>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id="when-&lt;file&gt;-does-not-exist">when &lt;file&gt; does not exist</h3>&#x000A;&#x000A;<h4 id="set-the-buffer-text-to-the-empty-string">set the buffer text to the empty string</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'foo'</span><span class="w">&#x000A;</span><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">file</span><span class="o">\</span><span class="n">delete</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="p">.</span><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">file</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">''</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span></pre>&#x000A;</div>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id=".eol-=-&lt;string&gt;">.eol = &lt;string&gt;</h2>&#x000A;&#x000A;<h4 id="raises-an-error-if-the-eol-is-unknown">raises an error if the eol is unknown</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'Unknown'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">buffer</span><span class="p">(</span><span class="s1">''</span><span class="p">).</span><span class="n">eol</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'foo'</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id=".multibyte">.multibyte</h2>&#x000A;&#x000A;<h4 id="returns-true-if-the-buffer-contains-multibyte-characters">returns true if the buffer contains multibyte characters</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">buffer</span><span class="p">(</span><span class="s1">'vanilla'</span><span class="p">).</span><span class="n">multibyte</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">buffer</span><span class="p">(</span><span class="s1">'HƏllo'</span><span class="p">).</span><span class="n">multibyte</span></pre>&#x000A;&#x000A;<h4 id="is-updated-whenever-text-is-inserted">is updated whenever text is inserted</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'vanilla'</span><span class="w">&#x000A;</span><span class="n">b</span><span class="o">\</span><span class="n">append</span><span class="w"> </span><span class="s1">'Bačon'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">multibyte</span></pre>&#x000A;&#x000A;<h4 id="is-updated-whenever-text-is-deleted">is updated whenever text is deleted</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'Bačon'</span><span class="w">&#x000A;</span><span class="n">b</span><span class="o">\</span><span class="n">delete</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">multibyte</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id=".modified_on_disk">.modified_on_disk</h2>&#x000A;&#x000A;<h4 id="is-false-for-a-buffer-with-no-file">is false for a buffer with no file</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="nc">Buffer</span><span class="o">!</span><span class="p">.</span><span class="n">modified_on_disk</span></pre>&#x000A;&#x000A;<h4 id="is-true-if-the-file's-etag-is-changed-after-a-load-or-save">is true if the file's etag is changed after a load or save</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">contents:</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="ss">etag:</span><span class="w"> </span><span class="s1">'1'</span><span class="p">,</span><span class="w"> </span><span class="ss">basename:</span><span class="w"> </span><span class="s1">'changeable'</span><span class="p">,</span><span class="w"> </span><span class="ss">exists:</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;</span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Buffer</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">b</span><span class="p">.</span><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">file</span><span class="w">&#x000A;</span><span class="n">file</span><span class="p">.</span><span class="n">etag</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'2'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">modified_on_disk</span><span class="w">&#x000A;</span><span class="n">b</span><span class="o">\</span><span class="n">save</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">modified_on_disk</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id=".config">.config</h2>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">config</span><span class="p">.</span><span class="n">define</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'buf_var'</span><span class="p">,</span><span class="w"> </span><span class="ss">description:</span><span class="w"> </span><span class="s1">'some var'</span><span class="p">,</span><span class="w"> </span><span class="ss">default:</span><span class="w"> </span><span class="s1">'def value'</span></pre>&#x000A;&#x000A;<h4 id="allows-reading-and-writing-(local)-variables">allows reading and writing (local) variables</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'config'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'def value'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">config</span><span class="p">.</span><span class="n">buf_var</span><span class="w">&#x000A;</span><span class="n">b</span><span class="p">.</span><span class="n">config</span><span class="p">.</span><span class="n">buf_var</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">123</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">123</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">config</span><span class="p">.</span><span class="n">buf_var</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'def value'</span><span class="p">,</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">buf_var</span></pre>&#x000A;&#x000A;<h4 id="is-chained-to-the-mode-config-when-available">is chained to the mode config when available</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">mode_config</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">local_proxy</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">mode</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">config:</span><span class="w"> </span><span class="n">mode_config</span><span class="w">&#x000A;</span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'config'</span><span class="w">&#x000A;</span><span class="n">b</span><span class="p">.</span><span class="n">mode</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">mode</span><span class="w">&#x000A;</span><span class="n">mode_config</span><span class="p">.</span><span class="n">buf_var</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'from_mode'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'from_mode'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">config</span><span class="p">.</span><span class="n">buf_var</span></pre>&#x000A;&#x000A;<h4 id="is-chained-to-the-global-config-when-mode-config-is-not-available">is chained to the global config when mode config is not available</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'config'</span><span class="w">&#x000A;</span><span class="n">b</span><span class="p">.</span><span class="n">mode</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'def value'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">config</span><span class="p">.</span><span class="n">buf_var</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="delete">delete<span class="arg-list">(start_pos, end_pos)</span></h2>&#x000A;&#x000A;<h4 id="deletes-the-specified-range,-inclusive">deletes the specified range, inclusive</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'ño örf'</span><span class="w">&#x000A;</span><span class="n">b</span><span class="o">\</span><span class="n">delete</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'ñrf'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span></pre>&#x000A;&#x000A;<h4 id="does-nothing-if-end_pos-is-smaller-than-start_pos">does nothing if end_pos is smaller than start_pos</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'hello'</span><span class="w">&#x000A;</span><span class="n">b</span><span class="o">\</span><span class="n">delete</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hello'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="insert">insert<span class="arg-list">(text, pos)</span></h2>&#x000A;&#x000A;<h4 id="inserts-text-at-pos">inserts text at pos</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'ño señor'</span><span class="w">&#x000A;</span><span class="n">b</span><span class="o">\</span><span class="n">insert</span><span class="w"> </span><span class="s1">'me gusta '</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'ño me gusta señor'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span></pre>&#x000A;&#x000A;<h4 id="returns-the-position-right-after-the-inserted-text">returns the position right after the inserted text</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">''</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">6</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">insert</span><span class="w"> </span><span class="s1">'Bačon'</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="append">append<span class="arg-list">(text)</span></h2>&#x000A;&#x000A;<h4 id="appends-the-specified-text">appends the specified text</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'hello'</span><span class="w">&#x000A;</span><span class="n">b</span><span class="o">\</span><span class="n">append</span><span class="w"> </span><span class="s1">' world'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hello world'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span></pre>&#x000A;&#x000A;<h4 id="returns-the-position-right-after-the-inserted-text">returns the position right after the inserted text</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">''</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">6</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">append</span><span class="w"> </span><span class="s1">'Bačon'</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="replace">replace<span class="arg-list">(pattern, replacement)</span></h2>&#x000A;&#x000A;<h4 id="replaces-all-occurences-of-pattern-with-replacement">replaces all occurences of pattern with replacement</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'hello\nuñi©ode\nworld\n'</span><span class="w">&#x000A;</span><span class="n">b</span><span class="o">\</span><span class="n">replace</span><span class="w"> </span><span class="s1">'[lo]'</span><span class="p">,</span><span class="w"> </span><span class="s1">''</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'he\nuñi©de\nwrd\n'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span></pre>&#x000A;&#x000A;<h4 id="returns-the-number-of-occurences-replaced">returns the number of occurences replaced</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'hello\nworld\n'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">replace</span><span class="p">(</span><span class="s1">'world'</span><span class="p">,</span><span class="w"> </span><span class="s1">'editor'</span><span class="p">)</span></pre>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when pattern contains a leading grouping)</span></h3>&#x000A;&#x000A;<h4 id="replaces-only-the-match-within-pattern-with-replacement">replaces only the match within pattern with replacement</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'hello\nworld\n'</span><span class="w">&#x000A;</span><span class="n">b</span><span class="o">\</span><span class="n">replace</span><span class="w"> </span><span class="s1">'(hel)lo'</span><span class="p">,</span><span class="w"> </span><span class="s1">''</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'lo\nworld\n'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span></pre>&#x000A;</div>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="change">change<span class="arg-list">(start_pos, end_pos, f)</span></h2>&#x000A;&#x000A;<h4 id="applies-all-operations-as-one-undo-for-the-specified-region">applies all operations as one undo for the specified region</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'ño señor'</span><span class="w">&#x000A;</span><span class="n">b</span><span class="o">\</span><span class="n">change</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="mi">6</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="c1">-- 'señ'</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="o">\</span><span class="n">delete</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="mi">6</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="o">\</span><span class="n">insert</span><span class="w"> </span><span class="s1">'minmin'</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="w">&#x000A;&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'ño minminor'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="w">&#x000A;</span><span class="n">b</span><span class="o">\</span><span class="n">undo</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'ño señor'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span></pre>&#x000A;&#x000A;<h4 id="returns-the-return-value-of-&lt;f&gt;-as-its-own-return-value">returns the return value of &lt;f&gt; as its own return value</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'12345'</span><span class="w">&#x000A;</span><span class="n">ret</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">change</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="s1">'zed'</span><span class="w">&#x000A;&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="s1">'zed'</span><span class="p">,</span><span class="w"> </span><span class="n">ret</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="undo">undo</h2>&#x000A;&#x000A;<h4 id="undoes-the-last-operation">undoes the last operation</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'hello'</span><span class="w">&#x000A;</span><span class="n">b</span><span class="o">\</span><span class="n">delete</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="w">&#x000A;</span><span class="n">b</span><span class="o">\</span><span class="n">undo</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hello'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span></pre>&#x000A;&#x000A;<h4 id="resets-the-.modified-flag-when-at-synced-file-revision">resets the .modified flag when at synced file revision</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">''</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="p">.</span><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">file</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hello'</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="o">\</span><span class="n">delete</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="o">\</span><span class="n">save</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="o">\</span><span class="n">delete</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="kc">true</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">modified</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="o">\</span><span class="n">undo</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="kc">false</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">modified</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="o">\</span><span class="n">undo</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="kc">true</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">modified</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="redo">redo</h2>&#x000A;&#x000A;<h4 id="redoes-the-last-undo-operation">redoes the last undo operation</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'hello'</span><span class="w">&#x000A;</span><span class="n">b</span><span class="o">\</span><span class="n">delete</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="w">&#x000A;</span><span class="n">b</span><span class="o">\</span><span class="n">undo</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">b</span><span class="o">\</span><span class="n">redo</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'ello'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span></pre>&#x000A;&#x000A;<h4 id="resets-the-.modified-flag-when-at-synced-file-revision">resets the .modified flag when at synced file revision</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">''</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="p">.</span><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">file</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hello'</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="o">\</span><span class="n">delete</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="o">\</span><span class="n">save</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="o">\</span><span class="n">delete</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="o">\</span><span class="n">undo</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="o">\</span><span class="n">undo</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="kc">true</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">modified</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="o">\</span><span class="n">redo</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="kc">false</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">modified</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="o">\</span><span class="n">redo</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="kc">true</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">modified</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id=".can_undo-=-&lt;bool&gt;">.can_undo = &lt;bool&gt;</h2>&#x000A;&#x000A;<h4 id="setting-it-to-false-removes-any-undo-history">setting it to false removes any undo history</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'hello'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">can_undo</span><span class="w">&#x000A;</span><span class="n">b</span><span class="p">.</span><span class="n">can_undo</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">false</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">can_undo</span><span class="w">&#x000A;</span><span class="n">b</span><span class="o">\</span><span class="n">undo</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'hello'</span></pre>&#x000A;&#x000A;<h4 id="setting-it-to-true-is-a-no-op">setting it to true is a no-op</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'hello'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">can_undo</span><span class="w">&#x000A;</span><span class="n">b</span><span class="p">.</span><span class="n">can_undo</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">can_undo</span><span class="w">&#x000A;</span><span class="n">b</span><span class="o">\</span><span class="n">undo</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">b</span><span class="p">.</span><span class="n">can_undo</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">can_undo</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id=".collect_revisions">.collect_revisions</h2>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when set to false)</span></h3>&#x000A;&#x000A;<h4 id="does-not-collect-undo-information">does not collect undo information</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Buffer</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">b</span><span class="p">.</span><span class="n">collect_revisions</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">false</span><span class="w">&#x000A;</span><span class="n">b</span><span class="o">\</span><span class="n">append</span><span class="w"> </span><span class="s1">'foo!'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">can_undo</span></pre>&#x000A;&#x000A;<h4 id="clears-existing-undo-information">clears existing undo information</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'zed'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">can_undo</span><span class="w">&#x000A;</span><span class="n">b</span><span class="p">.</span><span class="n">collect_revisions</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">false</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">can_undo</span></pre>&#x000A;</div>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="as_one_undo">as_one_undo<span class="arg-list">(f)</span></h2>&#x000A;&#x000A;<h4 id="allows-for-grouping-actions-as-one-undo">allows for grouping actions as one undo</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'hello'</span><span class="w">&#x000A;</span><span class="n">b</span><span class="o">\</span><span class="n">as_one_undo</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="o">\</span><span class="n">delete</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="o">\</span><span class="n">append</span><span class="w"> </span><span class="s1">'foo'</span><span class="w">&#x000A;</span><span class="n">b</span><span class="o">\</span><span class="n">undo</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hello'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span></pre>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when f raises an error)</span></h3>&#x000A;&#x000A;<h4 id="propagates-the-error">propagates the error</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'hello'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'oh my'</span><span class="p">,</span><span class="w">  </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="o">\</span><span class="n">as_one_undo</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="nb">error</span><span class="w"> </span><span class="s1">'oh my'</span></pre>&#x000A;&#x000A;<h4 id="ends-the-undo-transaction">ends the undo transaction</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'hello'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">error</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">as_one_undo</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="o">\</span><span class="n">delete</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="w">&#x000A;  </span><span class="nb">error</span><span class="w"> </span><span class="s1">'oh noes what happened?!?'</span><span class="w">&#x000A;</span><span class="n">b</span><span class="o">\</span><span class="n">append</span><span class="w"> </span><span class="s1">'foo'</span><span class="w">&#x000A;</span><span class="n">b</span><span class="o">\</span><span class="n">undo</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'ello'</span></pre>&#x000A;</div>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="save">save<span class="arg-list">()</span></h2>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when a file is assigned)</span></h3>&#x000A;&#x000A;<h4 id="stores-the-contents-of-the-buffer-in-the-assigned-file">stores the contents of the buffer in the assigned file</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'line1\nline2♥\nåäö\n'</span><span class="w">&#x000A;</span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="n">text</span><span class="w">&#x000A;</span><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="p">.</span><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">file</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">text</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="o">\</span><span class="n">save</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="n">file</span><span class="p">.</span><span class="n">contents</span></pre>&#x000A;&#x000A;<h4 id="clears-the-modified-flag">clears the modified flag</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'foo'</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="p">.</span><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">file</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="o">\</span><span class="n">append</span><span class="w"> </span><span class="s1">' bar'</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">modified</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="o">\</span><span class="n">save</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">modified</span></pre>&#x000A;<div class="spec-group spec-group-4">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(..  when config.strip_trailing_whitespace is false)</span></h3>&#x000A;&#x000A;<h4 id="does-not-strip-trailing-whitespace-before-saving">does not strip trailing whitespace before saving</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">config</span><span class="p">.</span><span class="n">strip_trailing_whitespace</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">false</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">''</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="p">.</span><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">file</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'blank  \n\nfoo \n'</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="o">\</span><span class="n">save</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'blank  \n\nfoo \n'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">file</span><span class="p">.</span><span class="n">contents</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-4">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(..  when config.strip_trailing_whitespace is true)</span></h3>&#x000A;&#x000A;<h4 id="strips-trailing-whitespace-at-the-end-of-lines-before-saving">strips trailing whitespace at the end of lines before saving</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">config</span><span class="p">.</span><span class="n">strip_trailing_whitespace</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">''</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="p">.</span><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">file</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'åäö  \n\nfoo  \n  '</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="o">\</span><span class="n">save</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'åäö\n\nfoo\n'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">file</span><span class="p">.</span><span class="n">contents</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-4">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(..  when config.ensure_newline_at_eof is true)</span></h3>&#x000A;&#x000A;<h4 id="appends-a-newline-if-necessary">appends a newline if necessary</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">config</span><span class="p">.</span><span class="n">ensure_newline_at_eof</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">''</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="p">.</span><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">file</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'look mah no newline!'</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="o">\</span><span class="n">save</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'look mah no newline!\n'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">file</span><span class="p">.</span><span class="n">contents</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-4">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(..  when config.ensure_newline_at_eof is false)</span></h3>&#x000A;&#x000A;<h4 id="does-not-appends-a-newline">does not appends a newline</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">config</span><span class="p">.</span><span class="n">ensure_newline_at_eof</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">false</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">''</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="p">.</span><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">file</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'look mah no newline!'</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="o">\</span><span class="n">save</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'look mah no newline!'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">file</span><span class="p">.</span><span class="n">contents</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span></pre>&#x000A;</div>&#x000A;</div>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="save_as">save_as<span class="arg-list">(file)</span></h2>&#x000A;&#x000A;<h4 id="associates-the-buffer-with-&lt;file&gt;-henceforth">associates the buffer with &lt;file&gt; henceforth</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">file</span><span class="p">.</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'orig'</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">''</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="p">.</span><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">file</span><span class="w">&#x000A;  </span><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">new_file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;    </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'nuevo'</span><span class="w">&#x000A;    </span><span class="n">b</span><span class="o">\</span><span class="n">save_as</span><span class="w"> </span><span class="n">new_file</span><span class="w">&#x000A;    </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'nuevo'</span><span class="p">,</span><span class="w"> </span><span class="n">new_file</span><span class="p">.</span><span class="n">contents</span><span class="w">&#x000A;    </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">new_file</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">file</span></pre>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when &lt;file&gt; does not exist)</span></h3>&#x000A;&#x000A;<h4 id="saves-the-buffer-content-in-the-newly-created-file">saves the buffer content in the newly created file</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">file</span><span class="o">\</span><span class="n">delete</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'new'</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="o">\</span><span class="n">save_as</span><span class="w"> </span><span class="n">file</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'new'</span><span class="p">,</span><span class="w"> </span><span class="n">file</span><span class="p">.</span><span class="n">contents</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when &lt;file&gt; exists)</span></h3>&#x000A;&#x000A;<h4 id="overwrites-any-previous-content-with-the-buffer-contents">overwrites any previous content with the buffer contents</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">file</span><span class="p">.</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'old'</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'new'</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="o">\</span><span class="n">save_as</span><span class="w"> </span><span class="n">file</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'new'</span><span class="p">,</span><span class="w"> </span><span class="n">file</span><span class="p">.</span><span class="n">contents</span></pre>&#x000A;</div>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="byte_offset">byte_offset<span class="arg-list">(char_offset)</span></h2>&#x000A;&#x000A;<h4 id="returns-the-byte-offset-for-the-given-&lt;char_offset&gt;">returns the byte offset for the given &lt;char_offset&gt;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'äåö'</span><span class="w">&#x000A;</span><span class="k">for</span><span class="w"> </span><span class="n">p</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="o">*</span><span class="p">{</span><span class="w">&#x000A;  </span><span class="p">{</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">},</span><span class="w">&#x000A;  </span><span class="p">{</span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">},</span><span class="w">&#x000A;  </span><span class="p">{</span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">},</span><span class="w">&#x000A;  </span><span class="p">{</span><span class="mi">7</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="p">},</span><span class="w">&#x000A;</span><span class="p">}</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">p</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">byte_offset</span><span class="w"> </span><span class="n">p</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span></pre>&#x000A;&#x000A;<h4 id="adjusts-out-of-bounds-offsets">adjusts out-of-bounds offsets</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">7</span><span class="p">,</span><span class="w">  </span><span class="n">buffer</span><span class="s1">'äåö'</span><span class="o">\</span><span class="n">byte_offset</span><span class="w"> </span><span class="mi">5</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">7</span><span class="p">,</span><span class="w">  </span><span class="n">buffer</span><span class="s1">'äåö'</span><span class="o">\</span><span class="n">byte_offset</span><span class="w"> </span><span class="mi">10</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w">  </span><span class="n">buffer</span><span class="s1">'äåö'</span><span class="o">\</span><span class="n">byte_offset</span><span class="w"> </span><span class="mi">0</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w">  </span><span class="n">buffer</span><span class="s1">'äåö'</span><span class="o">\</span><span class="n">byte_offset</span><span class="w"> </span><span class="o">-</span><span class="mi">1</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="char_offset">char_offset<span class="arg-list">(byte_offset)</span></h2>&#x000A;&#x000A;<h4 id="returns-the-character-offset-for-the-given-&lt;byte_offset&gt;">returns the character offset for the given &lt;byte_offset&gt;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'äåö'</span><span class="w">&#x000A;</span><span class="k">for</span><span class="w"> </span><span class="n">p</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="o">*</span><span class="p">{</span><span class="w">&#x000A;  </span><span class="p">{</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">},</span><span class="w">&#x000A;  </span><span class="p">{</span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">},</span><span class="w">&#x000A;  </span><span class="p">{</span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">},</span><span class="w">&#x000A;  </span><span class="p">{</span><span class="mi">7</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="p">},</span><span class="w">&#x000A;</span><span class="p">}</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">p</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">char_offset</span><span class="w"> </span><span class="n">p</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span></pre>&#x000A;&#x000A;<h4 id="adjusts-out-of-bounds-offsets">adjusts out-of-bounds offsets</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="s1">'ab'</span><span class="o">\</span><span class="n">char_offset</span><span class="w"> </span><span class="mi">4</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="s1">'äåö'</span><span class="o">\</span><span class="n">char_offset</span><span class="w"> </span><span class="mi">0</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="s1">'a'</span><span class="o">\</span><span class="n">char_offset</span><span class="w"> </span><span class="o">-</span><span class="mi">1</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="sub">sub<span class="arg-list">(start_pos, end_pos)</span></h2>&#x000A;&#x000A;<h4 id="returns-the-text-between-start_pos-and-end_pos,-both-inclusive">returns the text between start_pos and end_pos, both inclusive</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'hållö\nhållö\n'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'h'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">sub</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'å'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">sub</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hållö'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">sub</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hållö\nhållö\n'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">sub</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">12</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'ållö'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">sub</span><span class="p">(</span><span class="mi">8</span><span class="p">,</span><span class="w"> </span><span class="mi">11</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'\n'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">sub</span><span class="p">(</span><span class="mi">12</span><span class="p">,</span><span class="w"> </span><span class="mi">12</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'\n'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">sub</span><span class="p">(</span><span class="mi">12</span><span class="p">,</span><span class="w"> </span><span class="mi">13</span><span class="p">)</span></pre>&#x000A;&#x000A;<h4 id="handles-negative-indices-by-counting-from-end">handles negative indices by counting from end</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'hållö\nhållö\n'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'\n'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">sub</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="o">-</span><span class="mi">1</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hållö\n'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">sub</span><span class="p">(</span><span class="o">-</span><span class="mi">6</span><span class="p">,</span><span class="w"> </span><span class="o">-</span><span class="mi">1</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hållö\nhållö\n'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">sub</span><span class="p">(</span><span class="o">-</span><span class="mi">12</span><span class="p">,</span><span class="w"> </span><span class="o">-</span><span class="mi">1</span><span class="p">)</span></pre>&#x000A;&#x000A;<h4 id="returns-empty-string-for-start_pos-&gt;-end_pos">returns empty string for start_pos &gt; end_pos</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'abc'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">''</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">sub</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">)</span></pre>&#x000A;&#x000A;<h4 id="handles-out-of-bounds-offsets-gracefully">handles out-of-bounds offsets gracefully</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="s1">''</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="s1">'abc'</span><span class="o">\</span><span class="n">sub</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="mi">6</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="s1">'abc'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="s1">'abc'</span><span class="o">\</span><span class="n">sub</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">6</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="find">find<span class="arg-list">(pattern [, init ])</span></h2>&#x000A;&#x000A;<h4 id="searches-forward">searches forward</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'ä öx'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">find</span><span class="w"> </span><span class="s1">'ä öx'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">find</span><span class="w"> </span><span class="s1">' ö'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">find</span><span class="w"> </span><span class="s1">'öx'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">find</span><span class="w"> </span><span class="s1">'x'</span><span class="w"> </span><span class="p">}</span></pre>&#x000A;&#x000A;<h4 id="searches-forward-from-init-when-specified">searches forward from init when specified</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'öåååö'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">find</span><span class="w"> </span><span class="s1">'åå'</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">find</span><span class="w"> </span><span class="s1">'åå'</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">find</span><span class="p">(</span><span class="s1">'åå'</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="p">)</span></pre>&#x000A;&#x000A;<h4 id="negative-init-specifies-offset-from-end">negative init specifies offset from end</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'öååååö'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">find</span><span class="w"> </span><span class="s1">'åå'</span><span class="p">,</span><span class="w"> </span><span class="o">-</span><span class="mi">3</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">find</span><span class="w"> </span><span class="s1">'åå'</span><span class="p">,</span><span class="w"> </span><span class="o">-</span><span class="mi">5</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">find</span><span class="p">(</span><span class="s1">'åå'</span><span class="p">,</span><span class="w"> </span><span class="o">-</span><span class="mi">2</span><span class="p">)</span></pre>&#x000A;&#x000A;<h4 id="returns-nil-for-out-of-bounds-init">returns nil for out of bounds init</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'abcde'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">find</span><span class="p">(</span><span class="s1">'a'</span><span class="p">,</span><span class="w"> </span><span class="o">-</span><span class="mi">6</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">find</span><span class="p">(</span><span class="s1">'a'</span><span class="p">,</span><span class="w"> </span><span class="mi">6</span><span class="p">)</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="rfind">rfind<span class="arg-list">(pattern [, init ])</span></h2>&#x000A;&#x000A;<h4 id="searches-backward-from-end">searches backward from end</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'äöxöx'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">rfind</span><span class="w"> </span><span class="s1">'äöx'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">rfind</span><span class="w"> </span><span class="s1">'öx'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">rfind</span><span class="w"> </span><span class="s1">'x'</span><span class="w"> </span><span class="p">}</span></pre>&#x000A;&#x000A;<h4 id="searches-backward-from-init-when-specified">searches backward from init when specified</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'öååååö'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">rfind</span><span class="w"> </span><span class="s1">'åå'</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">rfind</span><span class="w"> </span><span class="s1">'åå'</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">rfind</span><span class="p">(</span><span class="s1">'åå'</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">)</span></pre>&#x000A;&#x000A;<h4 id="negative-init-specifies-offset-from-end">negative init specifies offset from end</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'öååååö'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">rfind</span><span class="w"> </span><span class="s1">'åå'</span><span class="p">,</span><span class="w"> </span><span class="o">-</span><span class="mi">2</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">rfind</span><span class="w"> </span><span class="s1">'åå'</span><span class="p">,</span><span class="w"> </span><span class="o">-</span><span class="mi">4</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">rfind</span><span class="p">(</span><span class="s1">'åå'</span><span class="p">,</span><span class="w"> </span><span class="o">-</span><span class="mi">5</span><span class="p">)</span></pre>&#x000A;&#x000A;<h4 id="returns-nil-for-out-of-bounds-init">returns nil for out of bounds init</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'abcde'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">rfind</span><span class="p">(</span><span class="s1">'a'</span><span class="p">,</span><span class="w"> </span><span class="o">-</span><span class="mi">6</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">rfind</span><span class="p">(</span><span class="s1">'a'</span><span class="p">,</span><span class="w"> </span><span class="mi">6</span><span class="p">)</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="reload">reload<span class="arg-list">(force = false)</span></h2>&#x000A;&#x000A;<h4 id="reloads-the-buffer-contents-from-file-and-returns-true">reloads the buffer contents from file and returns true</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">''</span><span class="w">&#x000A;  </span><span class="n">file</span><span class="p">.</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hello'</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="p">.</span><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">file</span><span class="w">&#x000A;  </span><span class="n">file</span><span class="p">.</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'there'</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">reload</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'there'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span></pre>&#x000A;&#x000A;<h4 id="raises-an-error-if-the-buffer-is-not-associated-with-a-file">raises an error if the buffer is not associated with a file</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'file'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="nc">Buffer</span><span class="o">!\</span><span class="n">reload</span><span class="o">!</span></pre>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when the buffer is modified)</span></h3>&#x000A;&#x000A;<h4 id="leaves-the-buffer-alone-and-returns-false">leaves the buffer alone and returns false</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">''</span><span class="w">&#x000A;  </span><span class="n">file</span><span class="p">.</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hello'</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="p">.</span><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">file</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="o">\</span><span class="n">append</span><span class="w"> </span><span class="s1">' world'</span><span class="w">&#x000A;  </span><span class="n">file</span><span class="p">.</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'there'</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">reload</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hello world'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span></pre>&#x000A;&#x000A;<h4 id="specifying-&lt;force&gt;-as-true-reloads-the-buffer-anyway">specifying &lt;force&gt; as true reloads the buffer anyway</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">''</span><span class="w">&#x000A;  </span><span class="n">file</span><span class="p">.</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hello'</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="p">.</span><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">file</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="o">\</span><span class="n">append</span><span class="w"> </span><span class="s1">' world'</span><span class="w">&#x000A;  </span><span class="n">file</span><span class="p">.</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'there'</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">b</span><span class="o">\</span><span class="n">reload</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'there'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span></pre>&#x000A;</div>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id=".add_view_ref">.add_view_ref<span class="arg-list">()</span></h2>&#x000A;&#x000A;<h4 id="increments-the-number-of-viewers">increments the number of viewers</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">''</span><span class="w">&#x000A;</span><span class="n">b</span><span class="o">\</span><span class="n">add_view_ref</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">viewers</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id=".remove_view_ref">.remove_view_ref<span class="arg-list">()</span></h2>&#x000A;&#x000A;<h4 id="decrements-the-number-of-viewers">decrements the number of viewers</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">''</span><span class="w">&#x000A;</span><span class="n">b</span><span class="o">\</span><span class="n">add_view_ref</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">b</span><span class="o">\</span><span class="n">remove_view_ref</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">viewers</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="titles">titles</h2>&#x000A;&#x000A;<h4 id="uses-file-basename-as-the-default-title">uses file basename as the default title</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Buffer</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">b</span><span class="p">.</span><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">File</span><span class="p">(</span><span class="s1">'/path/to/file.ext'</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">title</span><span class="p">,</span><span class="w"> </span><span class="s1">'file.ext'</span></pre>&#x000A;&#x000A;<h4 id="setting-title-explicitly-overrides-default-title">setting title explicitly overrides default title</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Buffer</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">b</span><span class="p">.</span><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">File</span><span class="p">(</span><span class="s1">'/path/to/file.ext'</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">b</span><span class="p">.</span><span class="n">title</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'be something else'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">title</span><span class="p">,</span><span class="w"> </span><span class="s1">'be something else'</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="signals">signals</h2>&#x000A;&#x000A;<h4 id="buffer-saved-is-fired-whenever-a-buffer-is-saved">buffer-saved is fired whenever a buffer is saved</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">with_signal_handler</span><span class="w"> </span><span class="s1">'buffer-saved'</span><span class="p">,</span><span class="w"> </span><span class="kc">nil</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">handler</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'foo'</span><span class="w">&#x000A;  </span><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;    </span><span class="n">b</span><span class="p">.</span><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">file</span><span class="w">&#x000A;    </span><span class="n">b</span><span class="o">\</span><span class="n">save</span><span class="o">!</span><span class="w">&#x000A;&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">handler</span><span class="p">).</span><span class="n">was_called</span><span class="o">!</span></pre>&#x000A;&#x000A;<h4 id="text-inserted-is-fired-whenever-text-is-inserted-into-a-buffer">text-inserted is fired whenever text is inserted into a buffer</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">with_signal_handler</span><span class="w"> </span><span class="s1">'text-inserted'</span><span class="p">,</span><span class="w"> </span><span class="kc">nil</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">handler</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'foo'</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="o">\</span><span class="n">append</span><span class="w"> </span><span class="s1">'bar'</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">handler</span><span class="p">).</span><span class="n">was_called</span><span class="o">!</span></pre>&#x000A;&#x000A;<h4 id="text-deleted-is-fired-whenever-text-is-deleted-from-buffer">text-deleted is fired whenever text is deleted from buffer</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">with_signal_handler</span><span class="w"> </span><span class="s1">'text-inserted'</span><span class="p">,</span><span class="w"> </span><span class="kc">nil</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">handler</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'foo'</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="o">\</span><span class="n">delete</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">handler</span><span class="p">).</span><span class="n">was_called</span><span class="o">!</span></pre>&#x000A;&#x000A;<h4 id="text-changed-is-fired-whenever-text-is-change:d-from-buffer">text-changed is fired whenever text is change:d from buffer</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">with_signal_handler</span><span class="w"> </span><span class="s1">'text-changed'</span><span class="p">,</span><span class="w"> </span><span class="kc">nil</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">handler</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'foo'</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="o">\</span><span class="n">change</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;    </span><span class="n">b</span><span class="o">\</span><span class="n">delete</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">handler</span><span class="p">).</span><span class="n">was_called</span><span class="o">!</span></pre>&#x000A;&#x000A;<h4 id="buffer-modified-is-fired-whenever-a-buffer-is-modified">buffer-modified is fired whenever a buffer is modified</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">with_signal_handler</span><span class="w"> </span><span class="s1">'buffer-modified'</span><span class="p">,</span><span class="w"> </span><span class="kc">nil</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">handler</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'foo'</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="o">\</span><span class="n">append</span><span class="w"> </span><span class="s1">'bar'</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">handler</span><span class="p">).</span><span class="n">was_called</span><span class="o">!</span></pre>&#x000A;&#x000A;<h4 id="buffer-reloaded-is-fired-whenever-a-buffer-is-reloaded">buffer-reloaded is fired whenever a buffer is reloaded</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">with_signal_handler</span><span class="w"> </span><span class="s1">'buffer-reloaded'</span><span class="p">,</span><span class="w"> </span><span class="kc">nil</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">handler</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;    </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'foo'</span><span class="w">&#x000A;    </span><span class="n">b</span><span class="p">.</span><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">file</span><span class="w">&#x000A;    </span><span class="n">b</span><span class="o">\</span><span class="n">reload</span><span class="o">!</span><span class="w">&#x000A;    </span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">handler</span><span class="p">).</span><span class="n">was_called</span><span class="o">!</span></pre>&#x000A;&#x000A;<h4 id="buffer-mode-set-is-fired-whenever-a-buffer-has-its-mode-set">buffer-mode-set is fired whenever a buffer has its mode set</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">with_signal_handler</span><span class="w"> </span><span class="s1">'buffer-mode-set'</span><span class="p">,</span><span class="w"> </span><span class="kc">nil</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">handler</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'foo'</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="p">.</span><span class="n">mode</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">handler</span><span class="p">).</span><span class="n">was_called</span><span class="o">!</span></pre>&#x000A;&#x000A;<h4 id="buffer-title-set-is-fired-whenever-a-buffer-has-its-title-set">buffer-title-set is fired whenever a buffer has its title set</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">with_signal_handler</span><span class="w"> </span><span class="s1">'buffer-title-set'</span><span class="p">,</span><span class="w"> </span><span class="kc">nil</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">handler</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'foo'</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="p">.</span><span class="n">title</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'Sir Buffer'</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">handler</span><span class="p">).</span><span class="n">was_called</span><span class="o">!</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(resource management)</span></h3>&#x000A;&#x000A;<h4 id="buffers-are-collected-properly">buffers are collected properly</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'foobar'</span><span class="w">&#x000A;</span><span class="n">buffers</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">setmetatable</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">b</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="ss">__mode:</span><span class="w"> </span><span class="s1">'v'</span><span class="w">&#x000A;</span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;</span><span class="nb">collectgarbage</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">buffers</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span></pre>&#x000A;&#x000A;<h4 id="memory-usage-is-stable">memory usage is stable</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert_memory_stays_within</span><span class="w"> </span><span class="s1">'5Kb'</span><span class="p">,</span><span class="w"> </span><span class="mi">30</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'collect me!'</span></pre>&#x000A;</div>&#x000A;</div>
      <div class='footer text-muted'>
        <a href='/'>
          <img width="50" height="50" class="footer-logo" src="/images/howl.png" />
        </a>
        <div class='footer-follow'>
          <p>
            <a class='twitter-follow-button' data-lang='en' data-show-count='false' href='https://twitter.com/howleditor' rel='me'>
              Follow @howleditor
            </a>
          </p>
          <p>
            <a class='twitter-share-button' data-count='none' data-hashtags='howleditor' data-lang='en' data-text='The Howl Editor, a general purpose, light-weight customizable editor.' data-url='http://howl.io' href='https://twitter.com/share'>
              Tweet
            </a>
          </p>
        </div>
        <div class='footer-blurb'>
          <div>The Howl editor.</div>
          <div>
            Copyright 2012-2016
            <a class='alert-link' href='https://github.com/howl-editor/howl/contributors'>
              The Howl Developers.
            </a>
          </div>
        </div>
      </div>
    </div>
    <script>
      <!-- / GA -->
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
      ga('create', 'UA-45283282-1', 'howl.io');
      ga('send', 'pageview');
      <!-- / Twitter -->
      !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];
      if(!d.getElementById(id)){js=d.createElement(s);js.id=id;
      js.src="//platform.twitter.com/widgets.js";
      fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
    </script>
  </body>
</html>
